const BASE_URL = window.location.origin + '/api';

export const chatAPI = {
  // 发送聊天消息
  async sendMessage(data) {
    try {
      const url = new URL(`${BASE_URL}/ai/chat/ts`)
      
      const response = await fetch(url, {
        method: 'POST',
        body: data instanceof FormData ? data : 
          new URLSearchParams({ prompt: data })
      })

      if (!response.ok) {
        throw new Error(`HTTP error! status: ${response.status}`)
      }

      return response.body.getReader()
    } catch (error) {
      console.error('API Error:', error)
      throw error
    }
  },
}